<template>
  <h1>用户管理</h1>
  <div class="container">
    <el-table :data="users" border style="width: 100%" locale="zhCn">
      <el-table-column type="index" label="序号" width="180" />
      <el-table-column prop="username" label="用户名"></el-table-column>
      <el-table-column prop="create_time" label="创建时间"></el-table-column>
      <el-table-column prop="type" label="身份">
        <template #default="scope">
          <span v-if="scope.row.type == 2">企业用户</span>
          <span v-else>个人用户</span>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="学历（个人）"></el-table-column>
      <el-table-column prop="state" label="企业经营状况"></el-table-column>
      <el-table-column prop="code1" label="统一社会信用代码"></el-table-column>
      <el-table-column prop="code2" label="工商注册号"></el-table-column>
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-button type="danger" @click="del(scope.row.id)"> 删除 </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script setup lang="ts">
import request from "@/api";
import { Type } from "@/types";
import { ElMessage, ElMessageBox } from "element-plus";
import { reactive, ref } from "vue";
import copper from "@/components/copper.vue";
const visible = ref(false);
const typeName = ref("");
const selectId = ref(0);
const form = reactive({
  banner_img: "",
  text: "",
});
// 类型
const users = ref<Array<any>>([]);

// 列表请求
request.get("/getUserList").then((res) => {
  users.value = res.data;
});

const del = async (id: number) => {
  //  element确认框
  ElMessageBox.confirm("是否删除该用户？", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      await request({
        url: "/delUser",
        method: "post",
        params: {
          id,
        },
      });
      ElMessage.success("操作成功");
      request.get("/getUserList").then((res) => {
        users.value = res.data;
      });
    })
    .catch(() => {});
};
</script>
<style scoped lang="less"></style>
